package com.sl.core.engine.scripts;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapUtil;
import com.sl.core.utils.JsonUtil;

import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

public class FeeTest {
    public static void main(String[] args) {

        String json = FileUtil.readString("/Users/weixin/work/project/self/square-lake/square-lake-core/square-lake-engine/src/main/java/com/sl/core/engine/scripts/ss.json", Charset.defaultCharset());
        List<Map<Object, Object>> mapList = JsonUtil.toMapList(json, String.class, Object.class);
        BigDecimal totalSelfArrangedAmount = BigDecimal.ZERO;
        BigDecimal totalSelfExpensedAmount = BigDecimal.ZERO;
        for (Map<Object, Object> objectObjectMap : mapList) {
            BigDecimal selfArrangedAmount = MapUtil.get(objectObjectMap, "selfArrangedAmount", BigDecimal.class);
            BigDecimal selfExpensedAmount = MapUtil.get(objectObjectMap, "selfExpensedAmount", BigDecimal.class);

            /** 自理金额相加 */
            if(selfArrangedAmount!= null){
                totalSelfArrangedAmount = totalSelfArrangedAmount.add(selfArrangedAmount);
            }

            /** 自费金额相加 */
            if(selfExpensedAmount != null){
                totalSelfExpensedAmount = totalSelfExpensedAmount.add(selfExpensedAmount);
                if(totalSelfExpensedAmount==null){
                    totalSelfExpensedAmount = BigDecimal.ZERO;
                }

            }
        }
        System.out.println(totalSelfExpensedAmount);

        System.out.println(totalSelfArrangedAmount);
    }
}
